package com.jxpanda.starter.config.security.authentication;

import com.jxpanda.starter.config.security.token.Token;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * @author Panda
 */
@Data
@AllArgsConstructor
public class TokenAuthentication implements Authentication {

    private Token token;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return token.getAuthorities();
    }

    @Override
    public String getCredentials() {
        return token.getSignature();
    }

    @Override
    public Token getDetails() {
        return token;
    }

    @Override
    public Token getPrincipal() {
        return token;
    }

    @Override
    public boolean isAuthenticated() {
        return token.isCredentialsNonExpired();
    }

    @Override
    public void setAuthenticated(boolean token) throws IllegalArgumentException {

    }

    @Override
    public String getName() {
        return token.getUsername();
    }


}
